extends "../cTDA/cTDA.gd"
func _info():
	pass

func _connect():
	._connect()

func _extInit():
	._extInit()
	chaName = "流氓"
	lv = 2
	attCoe.atk = 17 / 8.5 * 2 / 2
	attCoe.maxHp = 630 / 112.5 / 2
	addSkillTxt("来去无影：开局0.2秒后跳到敌方后排并使用<拦路打劫>")
	addSkillTxt("拦路打劫：嘲讽敌9宫格内所有敌方，若自身在3s内死亡则对9宫格内所有敌人造成<lv*121 + 300%物攻>真伤；\n否则对9宫格内所有敌人造成33%物理伤害并附加1层眩晕，随后清除所有仇恨并冲刺到最远的敌方附近[cd:4s]<固化>")

var sk2t = 0
var sk2flag = 0

func _onBattleStart():
	._onBattleStart()
	sk2t = 0
	sk2flag = 0
	yield(reTimer(0.2),"timeout")
	var mv = Vector2(cell.x ,cell.y)
	if team == 1:mv.x = 9
	else:mv.x = 0
	var vs = [Vector2(0,0),Vector2(1,0),Vector2(-1,0),Vector2(0,1),Vector2(0,-1),Vector2(1,1),Vector2(-1,1),Vector2(-1,-1),Vector2(1,-1)]
	for i in vs:
		var v = mv+i
		if matCha(v) == null && sys.main.isMatin(v):
			if setCell(v) :
				var pos = sys.main.map.map_to_world(cell)
				ying(pos,position)
				position = pos
				aiCha = null
				break
	lldj()

func _upS():
	._upS()
	sk2t += 1
	if sk2t == 4:
		sk2t = 0
		lldj()

func lldj():
	var vs = [Vector2(1,0),Vector2(-1,0),Vector2(0,1),Vector2(0,-1),Vector2(1,1),Vector2(-1,1),Vector2(-1,-1),Vector2(1,-1)]
	for i in vs:
		if sys.main.isMatin(i + cell):
			var cha = matCha(i + cell)
			if !cha:continue
			if cha.get("team") != self.team:
				cha.aiCha = self
	sk2flag = 1
	yield(sys.get_tree().create_timer(3),"timeout")
	sk2flag = 0
	if !self.isDeath:
		for i in vs:
			if sys.main.isMatin(i + cell):
				var cha = matCha(i + cell)
				if !cha:continue
				if cha.get("team") != self.team:
					hurtChara(cha,att.atk*0.33,Chara.HurtType.PHY,Chara.AtkType.SKILL)
		var chas = getAllChas(1)
		chas.sort_custom(self,"sortbydis")
		for i in chas:
			if i.aiCha == self:
				i.aiCha = null
		jump(chas[0],self)

func _onDeath(atkinfo):
	if !self.isDeath:return
	if sk2flag:
		var vs = [Vector2(1,0),Vector2(-1,0),Vector2(0,1),Vector2(0,-1),Vector2(1,1),Vector2(-1,1),Vector2(-1,-1),Vector2(1,-1)]
		for i in vs:
			if sys.main.isMatin(i + cell):
				var cha = matCha(i + cell)
				if !cha:continue
				if cha.get("team") != self.team:
					hurtChara(cha,self.lv * 121 + att.atk * 3,Chara.HurtType.REAL,Chara.AtkType.SKILL)
	._onDeath(atkinfo)

func sortbydis(a,b):
	return dis(a.cell,cell) > dis(b.cell,cell)
